home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / cit_src_7H21.lha / sysdep2.c < prev    next >
C/C++ Source or Header  |  1997-08-10  |  45KB  |  1,839 lines

  1. #include "dos.h"
  2. #include "stdio.h"
  3. #include "ctdl.h"
  4. #include "string.h"
  5. #include "stdarg.h"
  6. /*#include "clib/dos_protos.h" */
  7. #include "minrexx.h"
  8. #define EXTERN extern
  9. #include "global_data.h"
  10.  
  11. #define CITADEL_REQUIRED_STACK  8192L
  12. #ifdef CTDL_BACKGROUND
  13. static long _stack              = CITADEL_REQUIRED_STACK;
  14. static char *_procname          = "CTDL";
  15. static long _priority           = 0;
  16. static long _BackGroundIO       = 1;
  17. extern BPTR _Backstdout;
  18. #endif
  19.  
  20.  
  21.  
  22.  
  23. /* CTDL EXTERNS */
  24. extern CONFIG cfg;
  25. extern char CallSysop;
  26. extern char whichIO;
  27. extern char onConsole; /* Where IO is ... */
  28. extern logBuffer logBuf;         /* Buffer for the pippuls       */
  29. extern aRoom  roomBuf;           /* Room buffer                  */
  30. extern char ForceNet,anyEcho;
  31.  
  32.  
  33. /* EXTERNS */
  34. void Save_Modem(char *,int ,char *);
  35. void Do_Stack_Check(void);
  36. void Dos_Error(long,char *);
  37. void ReActivate_Window(void);  /* allow window to be activated */
  38. int BufferModemFlush(void);
  39. int OpenSerialPorts(void);
  40. int CloseSerial(int final);
  41. void CloseSerialPorts(void);
  42. int Handle_Window_Msg(struct IntuiMessage *InMsg);
  43. int Handle_Little_Window_Msg(struct IntuiMessage *InMsg);
  44. int OpenLittleWindow(void);
  45. int CloseLittleWindow(void);
  46. int BufferConsoleFlush(void);
  47. int OpenConsoleStuff(void);
  48. int CloseConsoleStuff(void);
  49. struct Message *MyGetMsg(struct MsgPort *MyMsgPort);
  50. /*
  51. void  DebugIoRequest (char * string,struct IOExtSer *iorequest);
  52. void DebugIoStdReq(struct IOStdReq *Std);
  53. void Debug_Unit(   struct Unit *Un);
  54. void Debug_Device( struct Device *Dev);
  55. void Debug_Message(struct Message *Msg);
  56. void Debug_Device( struct Device *Dev);
  57. void Debug_space(void);
  58. */
  59. void timer(unsigned long t[2]);
  60. /* GLOBALS */
  61. extern char *VERSION;
  62. struct IntuitionBase *IntuitionBase = NULL;
  63. struct GfxBase       *GfxBase = NULL;
  64. /*struct Library       *ReqBase = NULL; */
  65. struct RastPort      *myScreensRPort = NULL;
  66. UWORD myScreensBLine = 6;
  67. char ConOpen = FALSE;
  68. char UsingREXX = FALSE;
  69. unsigned char conletter,serletter;
  70. short SerialOpen = 0,TimerOpen = 1,probval,oldfrom,serqueued = FALSE,conqueued = FALSE;
  71. struct IOStdReq    *consoleReadMsg   = NULL;
  72. struct MsgPort     *consoleReadPort  = NULL;
  73. struct IOStdReq    *consoleWriteMsg  = NULL;
  74. struct MsgPort     *consoleWritePort = NULL;
  75. struct IOExtSer    *mySerReadMsg     = NULL;
  76. struct MsgPort     *mySerReadPort    = NULL;
  77. struct IOExtSer    *mySerWriteMsg    = NULL;
  78. struct MsgPort     *mySerWritePort   = NULL;
  79. struct IOExtSer    *mySerStatusMsg   = NULL;
  80. struct MsgPort     *mySerStatusPort  = NULL;
  81. struct timerequest *myTimerMsg       = NULL;
  82. struct MsgPort     *myTimerPort      = NULL;
  83.  
  84. extern char logNetResults;
  85. extern FILE *netLog;
  86.  
  87. long char_out;                 /* total characters output */
  88. extern long char_in;           /* total characters input */
  89. extern long start_time;        /* total time for net session */
  90.  
  91. long total_time;               /* total time for all net sessions */
  92. long total_char_in;            /* totals for all time */
  93. long total_char_out;           /* totals for all time */
  94. int level;
  95.  
  96. #ifdef HANDLE_FALSE_CARRIER
  97. struct MsgPort     *SpecialMP;
  98. char SpecialMPName[32];
  99. struct MySpecialMessage
  100.   {
  101.   struct Message Message;
  102.   APTR FCAddress;
  103.  
  104.   }
  105. *SpecialMsg;
  106. #endif
  107. struct Screen *myScreen = NULL;
  108. struct NewScreen myNewScreen =
  109.   {
  110.   0,0,640,200,1,0,1,
  111.   HIRES, CUSTOMSCREEN, NULL, ">>>--> Citadel BBS <--<<<",
  112.   NULL, NULL
  113.  
  114.   };
  115.  
  116. char window_title[84];
  117. char NewScreenTitle[84];
  118. char lastuser[28];
  119. char NewWindowTitle[84];
  120. /*
  121. ** Screen/Window  Title format
  122. ** 1                   23                39
  123. ** [ Citadel Version | Date/Time stamp | System Status      ]
  124. ** 1                   25                              50
  125. ** [ Current User    | Current Room                   | Previous User     ]
  126. */
  127. struct Window *myWindow = NULL, *LittleWindow = NULL;
  128. struct NewWindow myNewWindow =
  129.   {
  130.   0,10,640,190,(UBYTE)-1,(UBYTE)-1,
  131.   CLOSEWINDOW,
  132.   SMART_REFRESH|NOCAREREFRESH|BORDERLESS|RMBTRAP|
  133.   WINDOWCLOSE|WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH,
  134.   NULL, NULL, NULL, NULL, NULL,
  135.   200,40, 1000,1000, CUSTOMSCREEN
  136.  
  137.   };
  138. long timerworks = FALSE;
  139. long timercount = 0;
  140. char internalserial;
  141. #ifdef HANDLE_FALSE_CARRIER
  142. char FalseCarrier = 0;
  143. #endif
  144. UBYTE OpenSerFlags;
  145. struct Task    *MyTask    = NULL;
  146. struct Process *MyProcess = NULL;
  147. struct CommandLineInterface *CLI;
  148. ULONG TStackSz, PStackSz, DefStackSz;
  149. char WBWindow,CLINum;
  150. #define TALKTOREXX
  151. #ifdef TALKTOREXX
  152. /*
  153. *   We need our include file.
  154. */
  155. #include "minrexx.h"
  156. /*
  157. *   These are the REXX functions defined at the bottom of the file.
  158. */
  159. int disp(struct RexxMsg *msg, struct rexxCommandList *dat, char *p);
  160. void rexxsetchat(struct RexxMsg *msg, char *p);
  161. void rexxsetecho(struct RexxMsg *msg, char *p);
  162. void rexxsetnud(struct RexxMsg *msg, char *p);
  163. void rexxexit(struct RexxMsg *msg, char *p);
  164. void rexxversion(struct RexxMsg *msg, char *p);
  165. void rexxserialenable(struct RexxMsg *msg, char *p);
  166. void rexxopenconsole(struct RexxMsg *msg, char *p);
  167. void rexxiconify(struct RexxMsg *msg, char *p);
  168. #ifdef HANDLE_FALSE_CARRIER
  169. void rexxcarrier(struct RexxMsg *msg, char *p);
  170. #endif
  171. /*
  172. *   Here is our command association list.  Note that in this case,
  173. *   we are setting the userdata field to be a function to call.
  174. *   Dispatch will still take place through moodisp(), so common head
  175. *   and tail stuff can go there.
  176. *
  177. *   Commands are all lower case, so we match either upper or lower.
  178. *   (This is a requirement of minrexx.)
  179. */
  180. struct rexxCommandList rcl[] =
  181.   {
  182.     { "setchat",          (APTR)rexxsetchat },
  183.     { "setecho",          (APTR)rexxsetecho },
  184.     { "setnouserdisable", (APTR)rexxsetnud },
  185.     { "exit",             (APTR)rexxexit },
  186.     { "version",          (APTR)rexxversion },
  187.     { "serialenable",     (APTR)rexxserialenable },
  188.     { "openconsole",      (APTR)rexxopenconsole },
  189.     { "iconify",          (APTR)rexxiconify },
  190.   #ifdef HANDLE_FALSE_CARRIER
  191.     { "carrier",          (APTR)rexxcarrier },
  192.   #endif
  193.     { NULL, NULL } };
  194. #endif
  195.  
  196. unsigned long Set_Timer(unsigned long oldtime ) /* return the delta from oldtime in microsecs*/
  197.   {
  198.   unsigned long clock[2];
  199.   timer(clock);      /* get old time */
  200.   return ( clock[0] - oldtime );
  201.   }
  202.  
  203. static char lognet[80];
  204. static char date2[6], date1[6];
  205. static void Write_Total_Data(void);
  206. void Read_Total_Data(void);
  207.  
  208. void Read_Total_Data()
  209.   {
  210.   char *mon;
  211.   FILE *ip;
  212.   int lyr, ldum;
  213.   if( cfg.Audit == 0 )return;
  214.   makeAuditName(lognet, "Network_stats.sys");
  215.   if( (ip = fopen(lognet, "r")) != NULL )
  216.     {
  217.     fread(&date1,         6, 1, ip);
  218.     fread(&total_time,    4, 1, ip);
  219.     fread(&total_char_in, 4, 1, ip);
  220.     fread(&total_char_out,4, 1, ip);
  221.     fclose(ip);
  222.     getCdate(&lyr,&mon,&ldum,&ldum,&ldum);
  223.     sprintf(date2,"%3s%2d",mon,lyr);      /* monthYear */
  224.     if( strcmp(date1,date2) != 0 )
  225.       {
  226.       /* reset, new month  */
  227.       getCdate(&lyr,&mon,&ldum,&ldum,&ldum);
  228.       sprintf(date1,"%3s%2d",mon,lyr);      /* monthYear */
  229.       total_time    = 0;
  230.       total_char_in = 0;
  231.       total_char_out= 0;
  232.       Write_Total_Data();
  233.       }
  234.     }
  235.   else   /* no file, create it */
  236.     {
  237.     getCdate(&lyr,&mon,&ldum,&ldum,&ldum);
  238.     sprintf(date1,"%3s%2d",mon,lyr);      /* monthYear */
  239.     total_time    = 0;
  240.     total_char_in  = 0;   /* new file */
  241.     total_char_out = 0;
  242.     Write_Total_Data();
  243.     }
  244.   }
  245.  
  246. static void Write_Total_Data()
  247.   {
  248.   FILE *ip;
  249.   if( cfg.Audit == 0 )return;
  250.   makeAuditName(lognet, "Network_stats.sys");
  251.   if( (ip = fopen(lognet, "w")) != NULL )
  252.     {
  253.     fwrite(date1,          6, 1, ip);
  254.     fwrite(&total_time,    4, 1, ip);
  255.     fwrite(&total_char_in, 4, 1, ip);
  256.     fwrite(&total_char_out,4, 1, ip);
  257.     fclose(ip);
  258.     }
  259.   }
  260.  
  261. void Compute_Data(char *name)
  262.   {
  263.   int lyr,ldum;
  264.   char *mon;
  265.   FILE *ip;
  266.   long cps;           /* computed data rate */
  267.   long work_time;
  268.   work_time = Set_Timer(start_time);
  269.   if( logNetResults )
  270.     {
  271.     cps = ( char_in + char_out ) / work_time;
  272.     splitF(netLog," Characters Input:%ld Characters Output:%ld  %ld cps\n", char_in, char_out, cps);
  273.     if( cfg.Audit  )
  274.       {
  275.       makeAuditName(lognet,"Network_Istats.sys");
  276.       if( (ip = fopen(lognet, "a")) != NULL)
  277.         {
  278.         getCdate(&lyr,&mon,&ldum,&ldum,&ldum);
  279.         sprintf(date2,"%3s%2d",mon,lyr);      /* monthYear */
  280.         fprintf(ip,"%s %20s %10ld %10ld %10ld\n",date2,name, char_in, char_out, work_time);
  281.         fclose(ip);
  282.         };
  283.  
  284.       };
  285.     }
  286.   Read_Total_Data();
  287.   total_time     += work_time;
  288.   total_char_in  += char_in;
  289.   total_char_out += char_out;
  290.   Write_Total_Data();
  291.   }
  292.  
  293. int nodie(void)
  294.   {
  295.   Do_Stack_Check();
  296.   return(0);
  297.  
  298.   }
  299. int openStuff(void)
  300.   {
  301.   int error;
  302.   extern char anyEcho;
  303.   extern char BpsSet;
  304.   extern long byteRate;
  305.   extern long BaudTable[];
  306.   #ifdef TALKTOREXX
  307.   /*
  308.   *   If we are talking to REXX, we need this additional local.
  309.   */
  310.   long rexxbit ;
  311.   #endif
  312.   Do_Stack_Check();
  313.   probval   = 99;
  314.   termWidth = 40;
  315.   total_char_in = total_char_out = 0;
  316.   IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",33);
  317.   if (!IntuitionBase)
  318.     {
  319.     Dos_Error(1,"Open intuition.Library failed");
  320.     probval = 1;
  321.     goto thisend;
  322.  
  323.     }
  324.   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  325.   if (!GfxBase)
  326.     {
  327.     Dos_Error(2,"Open graphics.library failed");
  328.     probval = 2;
  329.     goto thisend;
  330.  
  331.     }
  332. /*
  333.   ReqBase = (struct Library *)OpenLibrary("req.library",0);
  334.   if (!ReqBase)
  335.     {
  336.     Dos_Error(2,"Open req.library failed");
  337.     probval = 2;
  338.     goto thisend;
  339.  
  340.     }
  341. */
  342.   MyTask     = FindTask(0L);
  343.   MyProcess  = (struct Process *)MyTask;
  344.   CLI = (struct CommandLineInterface *)(MyProcess->pr_CLI << 2);
  345.   if( CLI )
  346.     {
  347.     DefStackSz = CLI->cli_DefaultStack << 2;
  348.     }
  349.   else
  350.     {
  351.     DefStackSz = MyProcess->pr_StackSize;
  352.     };
  353.   if( DefStackSz < CITADEL_REQUIRED_STACK )
  354.     {
  355.     printf("Current Default Stack = %ld\n",DefStackSz);
  356.     printf("This program needs a stack greater than %ld\n",CITADEL_REQUIRED_STACK);
  357.     Dos_Error(3,"Insufficient Stack Space allocated");
  358.     probval = 3;
  359.     goto thisend;
  360.  
  361.     }
  362.   WBWindow = cfg.DepData.ScreenDepth;
  363.   error    = OpenConsoleStuff();
  364.   if (error < 0)
  365.     {
  366.     Dos_Error(error,"Console Open Error");
  367.     probval = 11;
  368.     goto thisend;
  369.  
  370.     }
  371.   #ifdef CTDL_BACKGROUND
  372.   Close(_Backstdout);
  373.   _Backstdout = 0;
  374.   #endif
  375.   anyEcho = cfg.DepData.StartUpEcho;
  376.   onbreak(nodie);
  377.   error = OpenSerialPorts();
  378.   if (error == ERROR)
  379.     {
  380.     probval = 25;
  381.     Dos_Error(probval,"Open Serial Port Failed");
  382.     goto thisend;
  383.  
  384.     }
  385.   SerialOpen = FALSE;
  386.   myTimerPort = CreatePort(0,0);
  387.   if (!myTimerPort)
  388.     {
  389.     probval = 31;
  390.     Dos_Error(probval,"Create Port Failed");
  391.     goto thisend;
  392.  
  393.     }
  394.   myTimerMsg = (struct timerequest *)CreateExtIO(myTimerPort, sizeof(struct timerequest));
  395.   if (!myTimerMsg)
  396.     {
  397.     probval = 32;
  398.     Dos_Error(probval,"Create I/O Requests Failed");
  399.     goto thisend;
  400.  
  401.     }
  402.   TimerOpen = OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)myTimerMsg,0);
  403.   if (TimerOpen != 0)
  404.     {
  405.     probval = 33;
  406.     Dos_Error(probval,"Open timer.device failed");
  407.     goto thisend;
  408.  
  409.     }
  410.   timerworks = TRUE;
  411.   #ifdef TALKTOREXX
  412.   /*
  413.   *   For rexx, we open up a Rexx port, and send out the first command,
  414.   *   if there was one.  We send it out asynchronously; no reason not to.
  415.   */
  416.   sprintf(ARexx_Name,"Citadel_68K");
  417.   if( FindPort(ARexx_Name) != NULL )
  418.     {
  419.     sprintf(ARexx_Name,"Citadel_68K_%d",CLINum);
  420.     if( FindPort(ARexx_Name) != NULL )
  421.       {
  422.       printf("Unique ARexx_Port Name Failure:%s\n",ARexx_Name);
  423.       };
  424.     };
  425.   rexxbit = upRexxPort(ARexx_Name, rcl, "rexx", &disp) ;
  426.   if (rexxbit != 0)
  427.     {
  428.     UsingREXX = TRUE;
  429.     printf("Rexx Port Name [Citadel_68K]\n ");
  430.  
  431.     }
  432.   #endif
  433.   #ifdef HANDLE_FALSE_CARRIER
  434.   sPrintf(SpecialMPName,"Citadel68K_Spcl_%d",CLINum);
  435.   SpecialMP = CreatePort(SpecialMPName,0);
  436.   if (SpecialMP)
  437.     {
  438.     printf("Special Port Name [%s]\n ",SpecialMPName);
  439.     #ifdef AUTO_EXEC_FALSECARRIER
  440.     sPrintf(NewWindowTitle,"run jays:falsecarrier/fc %d",CLINum);
  441.     Execute(NewWindowTitle,0L,0L);
  442.     WaitPort(SpecialMP);
  443.     SpecialMsg = (struct MySpecialMsg *)GetMsg(SpecialMP);
  444.     if (SpecialMsg)
  445.       {
  446.       SpecialMsg->FCAddress = &FalseCarrier;
  447.       ReplyMsg((struct Message *)SpecialMsg);
  448.  
  449.       }
  450.     #endif
  451.  
  452.     }
  453.   #endif
  454.   if (!BpsSet)  byteRate = (BaudTable[cfg.sysBaud] / 10L);
  455.   thisend:
  456.   if (probval != 99)
  457.     {
  458.     fprintf(stderr, "Startup Error Code %d\n",probval);
  459.     }
  460.   else       printf("System Initialized ok\n");
  461.   strcpy(lastuser," ***None*** ");
  462.   return (probval);
  463.  
  464.   }
  465. void closeStuff(int oldprobval)
  466.   {
  467.   Do_Stack_Check();
  468.   #ifdef TALKTOREXX
  469.   /*
  470.   *   With Rexx, we need to bring the port down.  You might make this
  471.   *   part of exit() for programs that have multiple paths to exit.
  472.   */
  473.   if (UsingREXX) dnRexxPort() ;
  474.   #endif
  475.   #if HANDLE_FALSE_CARRIER
  476.   if (SpecialMP)  DeletePort(SpecialMP);
  477.   #endif
  478.   timerworks = FALSE;
  479.   if ((probval > 34) && !TimerOpen)  CloseDevice((struct IORequest *)myTimerMsg);
  480.   if ((probval > 33) && myTimerMsg)  DeleteExtIO((struct IORequest *)myTimerMsg);
  481.   if ((probval > 32) && myTimerPort) DeletePort(myTimerPort);
  482.   if ((probval > 25) && SerialOpen)  CloseSerial(TRUE);
  483.   if (probval > 25)  CloseSerialPorts();
  484.   if (probval > 11)  CloseConsoleStuff();
  485.   if (LittleWindow)  CloseWindow(LittleWindow);
  486. /*  if (ReqBase)  CloseLibrary(ReqBase); */
  487.   if (GfxBase)  CloseLibrary((struct Library *)GfxBase);
  488.   if (IntuitionBase)  CloseLibrary((struct Library *)IntuitionBase);
  489.  
  490.   }
  491.  
  492.  
  493. #define FULL_BUFFER ( 1279 )
  494. int DoBufferModem,BufferModemCount;
  495. UBYTE ModemBuffer[FULL_BUFFER+1];
  496. int DoBufferConsole,BufferConsoleCount;
  497. char ConsoleBuffer[128];
  498.  
  499. void BufferingOn(void)
  500.   {
  501.   Do_Stack_Check();
  502.   DoBufferModem = TRUE;
  503.   DoBufferConsole = TRUE;
  504.  
  505.   }
  506. void BufferingOff(void)
  507.   {
  508.   Do_Stack_Check();
  509.   DoBufferModem = FALSE;
  510.   BufferModemFlush();
  511.   DoBufferConsole = FALSE;
  512.   BufferConsoleFlush();
  513.  
  514.   }
  515. int BufferModemFlush(void)
  516.   {
  517.   Do_Stack_Check();
  518.   if (SerialOpen && BufferModemCount && gotCarrier())
  519.     {
  520.     mySerWriteMsg->IOSer.io_Data = (APTR)ModemBuffer;
  521.     mySerWriteMsg->IOSer.io_Length = BufferModemCount;
  522.     mySerWriteMsg->IOSer.io_Command = CMD_WRITE;
  523.     char_out += BufferModemCount;
  524.     DoIO((       struct IORequest *)mySerWriteMsg);
  525.     if (cfg.BoolFlags.debug)Save_Modem(ModemBuffer,BufferModemCount,"Out:");
  526.  
  527.     }
  528.   BufferModemCount = 0;
  529.   return(TRUE);
  530.  
  531.   }
  532. char static_send;
  533. char outMod(int character)
  534.   {
  535.   Do_Stack_Check();
  536.   if(DoBufferModem)
  537.     {
  538.     ModemBuffer[BufferModemCount++] = character;
  539.     if(BufferModemCount > FULL_BUFFER )
  540.       {
  541.       BufferModemFlush();
  542.  
  543.       }
  544.  
  545.     }
  546.   else
  547.     {
  548.     if (SerialOpen)
  549.       {
  550.       static_send = character;
  551.       mySerWriteMsg->IOSer.io_Data = (APTR)&static_send;
  552.       mySerWriteMsg->IOSer.io_Length = 1;
  553.       mySerWriteMsg->IOSer.io_Command = CMD_WRITE;
  554.       DoIO(       (struct IORequest *)mySerWriteMsg);
  555.       char_out++;
  556.       if (cfg.BoolFlags.debug)Save_Modem(&static_send,1,"Out:");
  557.  
  558.       }
  559.  
  560.     }
  561.   return(TRUE);
  562.  
  563.   }
  564. int QueueSerRead(int where)
  565.   {
  566.   Do_Stack_Check();
  567.   if (!serqueued && SerialOpen)
  568.     {
  569.     mySerReadMsg->IOSer.io_Command = CMD_READ;
  570.     mySerReadMsg->IOSer.io_Data = (APTR)&serletter;
  571.     mySerReadMsg->IOSer.io_Length = 1;
  572.     char_in++;
  573.     SendIO((struct IORequest *)mySerReadMsg);
  574.     serqueued = TRUE;
  575.  
  576.     }
  577.   return(TRUE);
  578.  
  579.   }
  580. int UnQueueSerRead(void)
  581.   {
  582.   Do_Stack_Check();
  583.   if (serqueued && SerialOpen)
  584.     {
  585.     AbortIO((struct IORequest *)mySerReadMsg);
  586.     WaitPort(mySerReadPort);
  587.     MyGetMsg(mySerReadPort);
  588.     serqueued = FALSE;
  589.  
  590.     }
  591.   return(TRUE);
  592.  
  593.   }
  594. int serPutStr(struct IOExtSer *mess,char *str)
  595.   {
  596.   Do_Stack_Check();
  597.   if (SerialOpen)
  598.     {
  599.     mySerWriteMsg->IOSer.io_Command = CMD_WRITE;
  600.     mySerWriteMsg->IOSer.io_Data = (APTR)str;
  601.     mySerWriteMsg->IOSer.io_Length = strlen(str);
  602.     char_out += mySerWriteMsg->IOSer.io_Length;
  603.     DoIO(       (struct IORequest *)mySerWriteMsg);
  604.     if (cfg.BoolFlags.debug)Save_Modem(str,mySerWriteMsg->IOSer.io_Length," In:");
  605.  
  606.     }
  607.   return(TRUE);
  608.  
  609.   }
  610. #ifdef NEEDED
  611. /*
  612. * This code provided by Gabriel Broner, a s/w engineer at CPT Corp.
  613. *
  614. * First argument is the mask, second argument is a non-ambiguous string to
  615. * check against.
  616. */
  617. testsamefn (s1, s2)
  618. char *s1, *s2;
  619.   {
  620.   Do_Stack_Check();
  621.   if (*s1 == 0)
  622.     {
  623.     if (*(s1 - 1) == '*' || *s2 == 0)
  624.     return TRUE;
  625.     return FALSE;
  626.  
  627.     }
  628.   if (*s2 == 0)
  629.   return FALSE;
  630.   if (*s1 == *s2 || *s1 == '?')
  631.   return testsamefn(s1 + 1, s2 + 1);
  632.   if (*s1 == '*')
  633.   return (testsamefn(s1+1, s2) || testsamefn(s1, s2+1));
  634.   return FALSE;
  635.  
  636.   }
  637. #endif
  638. int OpenSerialPorts(void)
  639.   {
  640.   int erred;
  641.   erred = 0;
  642.   Do_Stack_Check();
  643.   mySerReadPort = CreatePort(0,0);
  644.   if (!mySerReadPort)
  645.     {
  646.     erred = 1;
  647.     Dos_Error(erred,"Create Read Port Failed");
  648.  
  649.     }
  650.   if (!erred)
  651.     {
  652.     mySerReadMsg = (struct IOExtSer *)CreateExtIO(mySerReadPort, sizeof(struct IOExtSer));
  653.     if (!mySerReadMsg)
  654.       {
  655.       erred = 2;
  656.       Dos_Error(erred,"Create Read ExtIO Failed");
  657.  
  658.       }
  659.  
  660.     }
  661.   if (!erred)
  662.     {
  663.     mySerWritePort = CreatePort(0,0);
  664.     if (mySerWritePort == NULL)
  665.       {
  666.       erred = 3;
  667.       Dos_Error(erred,"Create Write Port Failed");
  668.  
  669.       }
  670.  
  671.     }
  672.   if (!erred)
  673.     {
  674.     mySerWriteMsg = (struct IOExtSer *)CreateExtIO(mySerWritePort, sizeof(struct IOExtSer));
  675.     if (mySerWriteMsg == NULL)
  676.       {
  677.       erred = 4;
  678.       Dos_Error(erred,"Create Write ExtIO Failed");
  679.  
  680.       }
  681.  
  682.     }
  683.   if (!erred)
  684.     {
  685.     mySerStatusPort = CreatePort(0,0);
  686.     if (mySerStatusPort == NULL)
  687.       {
  688.       erred = 5;
  689.       Dos_Error(erred,"Create Status Port Failed");
  690.  
  691.       }
  692.  
  693.     }
  694.   if (!erred)
  695.     {
  696.     mySerStatusMsg = (struct IOExtSer *)CreateExtIO(mySerStatusPort,
  697.     sizeof(struct IOExtSer));
  698.     if (mySerStatusMsg == NULL)
  699.       {
  700.       erred = 6;
  701.       Dos_Error(erred,"Create Status ExtIO Failed");
  702.  
  703.       }
  704.  
  705.     }
  706.   if (erred)
  707.     {
  708.     CloseSerialPorts();
  709.  
  710.     }
  711.   return((erred) ? 0 : 1);
  712.  
  713.   }
  714. int OpenSerial(int starting)
  715.   {
  716.   int serror;
  717.   extern long byteRate;
  718.   ULONG devnum;
  719.   char devname[32];
  720.   Do_Stack_Check();
  721.   if (!SerialOpen)
  722.     {
  723.     strncpy(devname,cfg.DepData.DevName,31);
  724.     devname[31] = '\0';
  725.     devnum = cfg.DepData.UnitNumber;
  726.     if (!strcmp(devname,"serial.device") && devnum != 0)
  727.     internalserial = TRUE;
  728.     else  internalserial = FALSE;
  729.     OpenSerFlags = SERF_XDISABLED | SERF_SHARED|SERF_RAD_BOOGIE;
  730.     if (cfg.DepData.Clock & SER_7WIRE)
  731.       {
  732.       OpenSerFlags |= SERF_7WIRE;
  733.       };
  734.     mySerReadMsg->io_SerFlags = OpenSerFlags;
  735.     serror = OpenDevice(devname,devnum,(struct IORequest *)mySerReadMsg,0);
  736.     if (serror != 0)
  737.       {
  738.       Dos_Error(serror,"Open Device for serial port failed");
  739.       return(ERROR);
  740.       };
  741.     mySerWriteMsg->io_SerFlags = OpenSerFlags;
  742.     serror = OpenDevice(devname,devnum,(struct IORequest *)mySerWriteMsg,0);
  743.     if (serror != 0)
  744.       {
  745.       Dos_Error(serror,"Open Device for serial port failed");
  746.       CloseDevice((struct IORequest *)mySerReadMsg);
  747.       return(ERROR);
  748.  
  749.       }
  750.     mySerStatusMsg->io_SerFlags = OpenSerFlags;
  751.     serror = OpenDevice(devname,devnum,(struct IORequest *)mySerStatusMsg,0);
  752.     if (serror != 0)
  753.       {
  754.       Dos_Error(serror,"Open Device for serial port failed");
  755.       CloseDevice((struct IORequest *)mySerReadMsg);
  756.       CloseDevice((struct IORequest *)mySerWriteMsg);
  757.       return(ERROR);
  758.  
  759.       }
  760.     mySerStatusMsg->io_RBufLen  = mySerReadMsg->io_RBufLen  = mySerWriteMsg->io_RBufLen = 2048;
  761.     mySerStatusMsg->io_ReadLen  = mySerReadMsg->io_ReadLen  = mySerWriteMsg->io_ReadLen = 8;
  762.     mySerStatusMsg->io_WriteLen = mySerReadMsg->io_WriteLen = mySerWriteMsg->io_WriteLen = 8;
  763.     mySerStatusMsg->io_StopBits = mySerReadMsg->io_StopBits = mySerWriteMsg->io_StopBits = 1;
  764.     mySerStatusMsg->io_TermArray.TermArray0 = mySerReadMsg->io_TermArray.TermArray0 = mySerWriteMsg->io_TermArray.TermArray0 = NULL;
  765.     mySerStatusMsg->io_TermArray.TermArray1 = mySerReadMsg->io_TermArray.TermArray1 = mySerWriteMsg->io_TermArray.TermArray1 = NULL;
  766.     mySerStatusMsg->IOSer.io_Command = SDCMD_SETPARAMS;
  767.     DoIO(       (struct IORequest *)mySerStatusMsg);
  768.     SerialOpen = TRUE;
  769.     if (byteRate != 0)
  770.       CitadelBaudRate(byteRate, "OpenSerial:byteRate");
  771.     else CitadelBaudRate(cfg.sysBaud,"OpenSerial:sysBaud");
  772.     QueueSerRead(1);
  773.  
  774.     }
  775.   return(TRUE);
  776.  
  777.   }
  778. int CloseSerial(int final)
  779.   {
  780.   Do_Stack_Check();
  781.   if (SerialOpen)
  782.     {
  783.     UnQueueSerRead();
  784.     CloseDevice((struct IORequest *)mySerStatusMsg);
  785.     CloseDevice((struct IORequest *)mySerWriteMsg);
  786.     CloseDevice((struct IORequest *)mySerReadMsg);
  787.     SerialOpen = FALSE;
  788.     return(FALSE);
  789.  
  790.     }
  791.   return(TRUE);
  792.  
  793.   }
  794. void CloseSerialPorts(void)
  795.   {
  796.   Do_Stack_Check();
  797.   if (mySerStatusMsg)
  798.     {
  799.     DeleteExtIO((struct IORequest *)mySerStatusMsg);
  800.     mySerStatusMsg = NULL;
  801.  
  802.     }
  803.   if (mySerWriteMsg)
  804.     {
  805.     DeleteExtIO((struct IORequest *)mySerWriteMsg);
  806.     mySerWriteMsg = NULL;
  807.  
  808.     }
  809.   if (mySerReadMsg)
  810.     {
  811.     DeleteExtIO((struct IORequest *)mySerReadMsg);
  812.     mySerReadMsg = NULL;
  813.  
  814.     }
  815.   if (mySerStatusPort)
  816.     {
  817.     DeletePort(mySerStatusPort);
  818.     mySerStatusPort = NULL;
  819.  
  820.     }
  821.   if (mySerWritePort)
  822.     {
  823.     DeletePort(mySerWritePort);
  824.     mySerWritePort = NULL;
  825.  
  826.     }
  827.   if (mySerReadPort)
  828.     {
  829.     DeletePort(mySerReadPort);
  830.     mySerReadPort = NULL;
  831.  
  832.     }
  833.  
  834.   }
  835. char time_in[30];
  836. char sstatus[30];
  837. int timeupdatecount,old_user;
  838. int old_shr, old_smn;
  839. void ScrTimeUpdate(int shr, int smn)
  840.   {
  841.   Do_Stack_Check();
  842.   timeupdatecount = 0;
  843.   if (!ConOpen) return;
  844.   if( old_shr == shr && old_smn == smn )return;
  845.   old_shr = shr;
  846.   old_smn = smn;
  847.   if (myScreensRPort)
  848.     {
  849.     sPrintf(NewScreenTitle,"Citadel 68K V%s%s|%2d:%02d %7s| %-30s"
  850.     ,VERSION,SysVers,shr,smn,formDate(),sstatus);
  851.     SetWindowTitles(myWindow,window_title,NewScreenTitle);
  852.     }
  853.  
  854.   }
  855. void ScrNewUser(void)
  856.   {
  857.   char temp_title[84],*smo;
  858.   int syr,sdy,shr,smn;
  859.   Do_Stack_Check();
  860.   getCdate(&syr,&smo,&sdy,&shr,&smn);
  861.   if (!ConOpen || !myWindow) return;
  862.   if (!old_user && logBuf.lbname[0])
  863.     {
  864.     sPrintf(time_in,"In: %2d:%02d                    ",shr,smn);
  865.     old_user = 1;
  866.  
  867.     }
  868.   if (!logBuf.lbname[0] && old_user)
  869.     {
  870.     strcpy(time_in," *** None ***               ");
  871.     old_user = 0;
  872.  
  873.     }
  874.   sPrintf(temp_title,"User:%-19s|Room:%-19s|%c%c%c%s|Last:%s"
  875.   ,logBuf.lbname,  roomBuf.rbname,
  876.   (cfg.BoolFlags.noChat) ?  ' ' : 'C',
  877.   (cfg.BoolFlags.debug)  ?  'D' : ' ',
  878.   (anyEcho)              ?  'E' : ' ',
  879.   (CallSysop)            ? "^T" :((ForceNet) ? "^A" : "  "),
  880.   lastuser);
  881.   strncpy(window_title,temp_title,83);
  882.   old_smn = -1;
  883.   SpecialMessage(time_in);
  884.   }
  885. char oldmsg[30];
  886. void SpecialMessage(char *message)
  887.   {
  888.   short j;
  889.   char realmsg[30];
  890.   char *smo;
  891.   int syr,sdy,shr,smn;
  892.   Do_Stack_Check();
  893.   timeupdatecount = 0;
  894.   if (!ConOpen) return;
  895.   if (myScreensRPort)
  896.     {
  897.     j = strlen(message);
  898.     memset(realmsg,'\0',30);
  899.     if( j > 29)j = 29;
  900.     strncpy(realmsg,message,j);
  901.     realmsg[j] = '\0';
  902.     if( strcmp(oldmsg,realmsg) != 0 )      /* do not update unless change*/
  903.       {
  904.       sprintf(sstatus,"%-30s",realmsg);
  905.       getCdate(&syr,&smo,&sdy,&shr,&smn);
  906.       ScrTimeUpdate(shr, smn);
  907.       strcpy(oldmsg,realmsg);
  908.       };
  909.     }
  910.  
  911.   }
  912. /************************************************************************/
  913. /*   pause() busy-waits N/100 seconds            */
  914. /************************************************************************/
  915. void pause(int i)
  916.   {
  917.   ULONG secs, micros;
  918.   Do_Stack_Check();
  919.   if( myTimerMsg == NULL)return;
  920.   secs = i / 100;
  921.   micros = (i - (secs * 100)) * 10000;
  922.   if (!secs && !micros)  micros = 10000;
  923.   if (micros < 0 || micros > 999999)
  924.     {
  925.     printf("[pause(%d) micros = %ld]",i,micros);
  926.     micros = 10000;
  927.  
  928.     }
  929.   myTimerMsg->tr_node.io_Command = TR_ADDREQUEST;
  930.   myTimerMsg->tr_node.io_Message.mn_ReplyPort = myTimerPort;
  931.   myTimerMsg->tr_time.tv_secs = secs;
  932.   myTimerMsg->tr_time.tv_micro = micros;
  933.   DoIO((struct IORequest *)myTimerMsg);
  934.  
  935.   }
  936. void MilliSecPause(int x)
  937.   {  /* really a 100 microsecond delay per x */
  938.   long micros;
  939.   Do_Stack_Check();
  940.   if( myTimerMsg == NULL)return;
  941.   if( x < 1 || x > 1000)x = 1000;  /* out of range, give max */
  942.   micros = x * 100;                /* time in 100 microsecond units */
  943.   myTimerMsg->tr_node.io_Command = TR_ADDREQUEST;
  944.   myTimerMsg->tr_node.io_Message.mn_ReplyPort = myTimerPort;
  945.   myTimerMsg->tr_time.tv_secs  = 0;
  946.   myTimerMsg->tr_time.tv_micro = micros;
  947.   DoIO((struct IORequest *)myTimerMsg);
  948.  
  949.   }
  950. void timer(unsigned long t[2])
  951.   {
  952.   Do_Stack_Check();
  953.   if( myTimerMsg == NULL)return;
  954.   myTimerMsg->tr_node.io_Message.mn_ReplyPort = myTimerPort;
  955.   myTimerMsg->tr_node.io_Command = TR_GETSYSTIME;
  956.   DoIO((struct IORequest *)myTimerMsg);
  957.   t[0] = myTimerMsg->tr_time.tv_secs;
  958.   t[1] = myTimerMsg->tr_time.tv_micro;
  959.  
  960.   }
  961. #ifdef TALKTOREXX
  962. /*
  963. *   Now we get into the actual code necessary for our REXX port; functions
  964. *   that do the real work.  Note that this program was not structured
  965. *   particularly nicely for Rexx; I had to write each of these functions.
  966. *   Many programs have these subroutines already in place; they are called
  967. *   as part of the event loop.  This progam, however, just has one big
  968. *   switch statement with different actions . . .
  969. *
  970. *   First, our locals.
  971. */
  972. int args[4] ;              /* what args did we see to this function? */
  973. int parsed ;               /* was argument parsing successful? */
  974. int userreplied ;          /* has the current message been replied to yet? */
  975. /*
  976. *   This function takes a pointer to a pointer to a string, grabs the
  977. *   next number, returns it, and advances the pointer to the string to
  978. *   point after the number.
  979. */
  980. int getnm(char **where)
  981.   {
  982.   register char *p = *where ;
  983.   register int val = 0 ;
  984.   int gotone = 0 ;
  985.   Do_Stack_Check();
  986.   while (*p <= ' ' && *p)  p++ ;
  987.   while ('0' <= *p && *p <= '9')
  988.     {
  989.     gotone = 1 ;
  990.     val = 10 * val + *p++ - '0' ;
  991.  
  992.     }
  993.   if (gotone == 0)  parsed = 0 ;
  994.   *where = p ;
  995.   return(val) ;
  996.  
  997.   }
  998. /*
  999. *   This function trys to find `n' numeric arguments in the command
  1000. *   string, and stuffs them into the args array.
  1001. */
  1002. void parseargs(char *p, int n)
  1003.   {
  1004.   register int i ;
  1005.   Do_Stack_Check();
  1006.   while (*p > ' ' && *p)  p++ ;
  1007.   for (i=0; i<n; i++)  args[i] = getnm(&p) ;
  1008.  
  1009.   }
  1010. /*
  1011. *   This is our main dispatch function.  We check to make sure a Window
  1012. *   currently exists.  Then, we store away the `current color' and change
  1013. *   it to Rexx's current color, call our handler function, and then restore
  1014. *   the color.  If our handler replied, we return a 1 to indicate that.
  1015. *   If the parse and everything else was successful, we return a 0.
  1016. *   Otherwise, we return a failure of 20 to indicate that the arguments
  1017. *   were messed up.
  1018. */
  1019. int disp(struct RexxMsg *msg, struct rexxCommandList *dat, char *p)
  1020.   {
  1021.   parsed = 1 ;
  1022.   Do_Stack_Check();
  1023.   userreplied = 0 ;
  1024.   ((int (*)())(dat->userdata))(msg, p) ;
  1025.   if (! parsed) replyRexxCmd(msg, (long)parsed, 0L, NULL) ;
  1026.   return TRUE;
  1027.  
  1028.   }
  1029. #endif
  1030. #ifdef TALKTOREXX
  1031. char dorexxexit = FALSE;
  1032. #endif
  1033. int Amiga_System_Input(void)
  1034.   {
  1035.   struct IntuiMessage *InMsg;
  1036.   Do_Stack_Check();
  1037.   #ifdef TALKTOREXX
  1038.   /*
  1039.   *   Handle any Rexx messages.
  1040.   */
  1041.   if (UsingREXX)  dispRexxPort() ;
  1042.   #endif
  1043.   #ifdef HANDLE_FALSE_CARRIER
  1044.   if (SpecialMP)
  1045.     {
  1046.     SpecialMsg = (struct MySpecialMsg *)GetMsg(SpecialMP);
  1047.     if (SpecialMsg)
  1048.       {
  1049.       SpecialMsg->FCAddress = &FalseCarrier;
  1050.       ReplyMsg(SpecialMsg);
  1051.  
  1052.       }
  1053.  
  1054.     }
  1055.   #endif
  1056.   if (ConOpen)
  1057.     {
  1058.     InMsg = (struct IntuiMessage *)GetMsg(myWindow->UserPort);
  1059.     if (InMsg != NULL) Handle_Window_Msg(InMsg);
  1060.  
  1061.     }
  1062.   if (LittleWindow != NULL)
  1063.     {
  1064.     InMsg = (struct IntuiMessage *)GetMsg(LittleWindow->UserPort);
  1065.     if (InMsg != NULL) Handle_Little_Window_Msg(InMsg);
  1066.  
  1067.     }
  1068.   return(0);
  1069.  
  1070.   }
  1071. #ifdef TALKTOREXX
  1072. void rexxsetchat(struct RexxMsg *msg, char *p)
  1073.   {
  1074.   Do_Stack_Check();
  1075.   parseargs(p, 1) ;
  1076.   cfg.BoolFlags.noChat = (args[0]) ? FALSE : TRUE;
  1077.   ScrNewUser();
  1078.  
  1079.   }
  1080. void rexxsetecho(struct RexxMsg *msg, char *p)
  1081.   {
  1082.   Do_Stack_Check();
  1083.   parseargs(p, 1) ;
  1084.   anyEcho = (args[0]) ? TRUE : FALSE;
  1085.   ScrNewUser();
  1086.  
  1087.   }
  1088. void rexxsetnud(struct RexxMsg *msg, char *p)
  1089.   {
  1090.   Do_Stack_Check();
  1091.   parseargs(p, 1) ;
  1092.   CallSysop = (args[0]) ? TRUE : FALSE;
  1093.   ScrNewUser();
  1094.  
  1095.   }
  1096. extern char haveCarrier;
  1097. char retstr[4];
  1098. void rexxexit(struct RexxMsg *msg, char *p)
  1099.   {
  1100.   Do_Stack_Check();
  1101.   parseargs(p, 1) ;
  1102.   strcpy(retstr,"0");
  1103.   if (!haveCarrier || args[0] != 0)
  1104.     {
  1105.     ExitToMsdos = TRUE;
  1106.     exitValue = 0;
  1107.     strcpy(retstr,"1");
  1108.  
  1109.     }
  1110.   userreplied = 1;
  1111.   replyRexxCmd(msg, 0L, 0L, retstr) ;
  1112.  
  1113.   }
  1114. void rexxversion(struct RexxMsg *msg, char *p)
  1115.   {
  1116.   Do_Stack_Check();
  1117.   userreplied = 1 ;
  1118.   replyRexxCmd(msg, 0L, 0L, VERSION) ;
  1119.  
  1120.   }
  1121. void rexxserialenable(struct RexxMsg *msg, char *p)
  1122.   {
  1123.   Do_Stack_Check();
  1124.   parseargs(p, 2) ;
  1125.   strcpy(retstr,"0");
  1126.   if (!haveCarrier || args[1] != 0)
  1127.     {
  1128.     if (args[0])
  1129.       {
  1130.       SerialOpen = OpenSerial(FALSE);
  1131.       if (SerialOpen == TRUE) strcpy(retstr,"1");
  1132.  
  1133.       }
  1134.     else
  1135.       {
  1136.       SerialOpen = CloseSerial(FALSE);
  1137.       if (!SerialOpen) strcpy(retstr,"1");
  1138.  
  1139.       }
  1140.  
  1141.     }
  1142.   userreplied = 1;
  1143.   replyRexxCmd(msg, 0L, 0L, retstr) ;
  1144.  
  1145.   }
  1146. void rexxopenconsole(struct RexxMsg *msg, char *p)
  1147.   {
  1148.   Do_Stack_Check();
  1149.   parseargs(p, 1) ;
  1150.   strcpy(retstr,"0");
  1151.   if (args[0])
  1152.     {
  1153.     if (!ConOpen)
  1154.       {
  1155.       OpenConsoleStuff();
  1156.       iconify_window = FALSE;
  1157.       };
  1158.     }
  1159.   else
  1160.     {
  1161.     if (ConOpen)
  1162.       {
  1163.       if (whichIO == MODEM)
  1164.         {
  1165.         CloseConsoleStuff();
  1166.         iconify_window = TRUE;
  1167.         };
  1168.       };
  1169.     };
  1170.   if (ConOpen)
  1171.   strcpy(retstr,"1");
  1172.   else
  1173.   strcpy(retstr,"0");
  1174.   userreplied = 1;
  1175.   replyRexxCmd(msg, 0L, 0L, retstr) ;
  1176.  
  1177.   }
  1178. void rexxiconify(struct RexxMsg *msg, char *p)
  1179.   {
  1180.   int error;
  1181.   Do_Stack_Check();
  1182.   parseargs(p, 1) ;
  1183.   strcpy(retstr,"0");
  1184.   if (args[0])
  1185.     {
  1186.     if (ConOpen)
  1187.       {
  1188.       if (whichIO == MODEM)
  1189.         {
  1190.         error = OpenLittleWindow();
  1191.         if (error == TRUE)
  1192.           {
  1193.           CloseConsoleStuff();
  1194.           strcpy(retstr,"1");
  1195.           iconify_window = TRUE;
  1196.           }
  1197.  
  1198.         }
  1199.  
  1200.       }
  1201.  
  1202.     }
  1203.   else
  1204.     {
  1205.     if (!ConOpen)
  1206.       {
  1207.       error = OpenConsoleStuff();
  1208.       if (error > 0)
  1209.         {
  1210.         strcpy(retstr,"1");
  1211.         if (LittleWindow != NULL)
  1212.         CloseLittleWindow();
  1213.         iconify_window = FALSE;
  1214.  
  1215.         }
  1216.  
  1217.       }
  1218.  
  1219.     }
  1220.  
  1221.   userreplied = 1;
  1222.   replyRexxCmd(msg, 0L, 0L, retstr) ;
  1223.  
  1224.   }
  1225. #ifdef HANDLE_FALSE_CARRIER
  1226. void rexxcarrier(struct RexxMsg *msg, char *p)
  1227.   {
  1228.   Do_Stack_Check();
  1229.   parseargs(p, 1) ;
  1230.   FalseCarrier = (args[0]) ? TRUE : FALSE;
  1231.  
  1232.   }
  1233. #endif
  1234. #endif
  1235. int Handle_Window_Msg(struct IntuiMessage *InMsg)
  1236.   {
  1237.   ULONG msgclass;
  1238.   int err;
  1239.   Do_Stack_Check();
  1240.   msgclass = InMsg->Class;
  1241.   ReplyMsg((struct Message *)InMsg);
  1242.   if (msgclass == CLOSEWINDOW)
  1243.     {
  1244.     if (whichIO == MODEM)
  1245.       {
  1246.       err = OpenLittleWindow();
  1247.       if (err == FALSE)
  1248.         {
  1249.         DisplayBeep(NULL);
  1250.  
  1251.         }
  1252.       else
  1253.         {
  1254.         CloseConsoleStuff();
  1255.  
  1256.         }
  1257.  
  1258.       }
  1259.  
  1260.     }
  1261.   return(TRUE);
  1262.  
  1263.   }
  1264. int Handle_Little_Window_Msg(struct IntuiMessage *InMsg)
  1265.   {
  1266.   int err;
  1267.   Do_Stack_Check();
  1268.   ReplyMsg((struct Message *)InMsg);
  1269.   err = OpenConsoleStuff();
  1270.   if (err < 1)
  1271.     {
  1272.     DisplayBeep(NULL);
  1273.  
  1274.     }
  1275.   else
  1276.     {
  1277.     CloseLittleWindow();
  1278.  
  1279.     }
  1280.   return(TRUE);
  1281.  
  1282.   }
  1283. struct NewWindow NewLittleWindow =
  1284.   {
  1285.   100,0,188,12,(UBYTE)-1,(UBYTE)-1,
  1286.   CLOSEWINDOW,
  1287.   WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | SMART_REFRESH | RMBTRAP,
  1288.   NULL, NULL,
  1289.   (UBYTE *)"Amiga Citadel",
  1290.   NULL,NULL,0,0,1000,1000,WBENCHSCREEN
  1291.  
  1292.   };
  1293. int OpenLittleWindow(void)
  1294.   {
  1295.   Do_Stack_Check();
  1296.   if (LittleWindow == NULL)
  1297.     {
  1298.     LittleWindow = OpenWindow(&NewLittleWindow);
  1299.  
  1300.     }
  1301.   if (LittleWindow != NULL)
  1302.   return(1);
  1303.   return(0);
  1304.  
  1305.   }
  1306. int CloseLittleWindow(void)
  1307.   {
  1308.   Do_Stack_Check();
  1309.   if (LittleWindow != NULL)
  1310.     {
  1311.     CloseWindow(LittleWindow);
  1312.     LittleWindow = NULL;
  1313.     return(1);
  1314.  
  1315.     }
  1316.   else return(0);
  1317.  
  1318.   }
  1319.  
  1320. int Jsystem(char *cmdline)
  1321.   {
  1322.   long ecode;
  1323.   char dir[80];
  1324.   BPTR nilfh;
  1325.   Do_Stack_Check();
  1326.   if (cfg.BoolFlags.debug)
  1327.     {
  1328.     (void)getcd(0,dir);
  1329.     splitF(netLog, " Dir:%s\n Command:%s\n",dir,cmdline);
  1330.     };
  1331.   (void)SetIoErr(0);       /* initialize the error code */
  1332.   pause(1);
  1333.   nilfh = Open("NIL:",MODE_OLDFILE);
  1334.   Execute(cmdline,NULL,nilfh);  /* execute the command */
  1335.   ecode = IoErr();          /* check for error */
  1336.   if( ecode != 0 )Dos_Error(ecode,cmdline);
  1337.   return((int)ecode);
  1338.   }
  1339.  
  1340. void Dos_Error(err,str)   /* format a AmigaDos Error and put in debug.sys */
  1341. long err;
  1342. char *str;
  1343.   {
  1344.   char *mon;
  1345.   int yr,day,hour,min;
  1346.   char buf[80];
  1347.   char CLogFn[80];            /* buffer for calllog.sys */
  1348.   Do_Stack_Check();
  1349.   if( cfg.Audit == 0)return;  /* exit if the Sysop has not configed Auditing*/
  1350.   makeAuditName(CLogFn, "debug.sys");
  1351.   getCdate(&yr,&mon,&day,&hour,&min);
  1352.   sprintf(buf,"%2d%s%02d %d:%02d - Dos Error:%ld",yr,mon,day,hour,min,err);
  1353.   CallMsg(CLogFn,buf);        /* time and date of the error */
  1354.   sprintf(buf,"%s",str);
  1355.   CallMsg(CLogFn, buf);       /* report the command */
  1356.   (void)Fault(err,"Reason:",buf,80);
  1357.   CallMsg(CLogFn, buf);       /* report the error in text */
  1358.   (void)getcd(0,buf);
  1359.   CallMsg(CLogFn, buf);       /* report the current directory */
  1360.   pause(3);
  1361.   }
  1362.  
  1363. void ReActivate_Window()
  1364.   {
  1365.   Do_Stack_Check();
  1366.   if( !ConOpen ) OpenConsoleStuff();/* reactivate window if closed */
  1367.   ScreenToFront(myWindow->WScreen); /* make sure that the screen is front */
  1368.   WindowToFront(myWindow);          /* make sure the window is in front */
  1369.   ActivateWindow(myWindow);         /* activate, it can't hurt */
  1370.   }
  1371.  
  1372. int QueueRead(struct IOStdReq *request,char *whereto)
  1373.   {
  1374.   Do_Stack_Check();
  1375.   if (ConOpen && !conqueued)
  1376.     {
  1377.     consoleReadMsg->io_Command = CMD_READ;
  1378.     consoleReadMsg->io_Data = (APTR)&conletter;
  1379.     consoleReadMsg->io_Length = 1;
  1380.     SendIO((struct IORequest *)consoleReadMsg);
  1381.     conqueued = TRUE;
  1382.  
  1383.     }
  1384.   return(TRUE);
  1385.  
  1386.   }
  1387. int UnQueueRead(void)
  1388.   {
  1389.   Do_Stack_Check();
  1390.   if (conqueued && ConOpen)
  1391.     {
  1392.     AbortIO((struct IORequest *)consoleReadMsg);
  1393.     WaitPort(consoleReadPort);
  1394.     MyGetMsg(consoleReadPort);
  1395.     conqueued = FALSE;
  1396.  
  1397.     }
  1398.   return(TRUE);
  1399.  
  1400.   }
  1401. int ConPutStr(char *myString)
  1402.   {
  1403.   Do_Stack_Check();
  1404.   if (!ConOpen || !myString || !strlen(myString))  return(0);
  1405.   consoleWriteMsg->io_Command = CMD_WRITE;
  1406.   consoleWriteMsg->io_Data = (APTR)myString;
  1407.   consoleWriteMsg->io_Length = strlen(myString);
  1408.   DoIO((struct IORequest *)consoleWriteMsg);
  1409.   return(1);
  1410.  
  1411.   }
  1412. int BufferConsoleFlush(void)
  1413.   {
  1414.   Do_Stack_Check();
  1415.   if (ConOpen && BufferConsoleCount)
  1416.     {
  1417.     consoleWriteMsg->io_Data = (APTR)ConsoleBuffer;
  1418.     consoleWriteMsg->io_Length = BufferConsoleCount;
  1419.     consoleWriteMsg->io_Command = CMD_WRITE;
  1420.     DoIO((struct IORequest *)consoleWriteMsg);
  1421.  
  1422.     }
  1423.   BufferConsoleCount = 0;
  1424.   return(TRUE);
  1425.  
  1426.   }
  1427. int ConPutChar(char myChar)
  1428.   {
  1429.   Do_Stack_Check();
  1430.   if (DoBufferConsole)
  1431.     {
  1432.     ConsoleBuffer[BufferConsoleCount++] = myChar;
  1433.     if(BufferConsoleCount > 126)
  1434.       {
  1435.       BufferConsoleFlush();
  1436.  
  1437.       }
  1438.  
  1439.     }
  1440.   else
  1441.     {
  1442.     if (ConOpen)
  1443.       {
  1444.       consoleWriteMsg->io_Command = CMD_WRITE;
  1445.       consoleWriteMsg->io_Data = (APTR)&myChar;
  1446.       consoleWriteMsg->io_Length = 1;
  1447.       DoIO((struct IORequest *)consoleWriteMsg);
  1448.  
  1449.       }
  1450.  
  1451.     }
  1452.   return(TRUE);
  1453.  
  1454.   }
  1455. int OpenConsoleStuff(void)
  1456.   {
  1457.   UWORD tmpcolors[2];
  1458.   int error,erred;
  1459.   Do_Stack_Check();
  1460.   if (ConOpen)  return(1);
  1461.   erred = 0;
  1462.   if (!WBWindow)
  1463.     {
  1464.     myNewScreen.Width     = cfg.DepData.ScreenWidth;
  1465.     myNewScreen.Height    = cfg.DepData.ScreenHeight;
  1466.     myNewScreen.Depth     = 1;  /* 3;   /* 8 colors */
  1467.     if (cfg.DepData.ScreenHeight > 399) myNewScreen.ViewModes |= LACE;
  1468.     sPrintf(NewScreenTitle,"Amiga Citadel V%s %s",VERSION,SysVers);
  1469.     myNewScreen.DefaultTitle = (UBYTE *)NewScreenTitle;
  1470.     myScreen = (struct Screen *)OpenScreen(&myNewScreen);
  1471.     if (!myScreen) return(-1);
  1472.     myNewWindow.Screen = myScreen;
  1473.     myScreensRPort = &(myScreen->RastPort);
  1474.     myScreensBLine = myScreensRPort->Font->tf_Baseline + 1;
  1475.  
  1476.     }
  1477.   else
  1478.     {
  1479.     myNewWindow.Type    = WBENCHSCREEN;
  1480.     myNewWindow.Screen  = NULL;
  1481.     myScreensRPort      = NULL;
  1482.     myNewWindow.TopEdge = 0;
  1483.  
  1484.     }
  1485.   strcpy(NewWindowTitle,"Citadel Console");
  1486.   myNewWindow.Title = (UBYTE *)NewWindowTitle;
  1487.   myNewWindow.Width = cfg.DepData.ScreenWidth;
  1488.   if (!WBWindow)
  1489.     {
  1490.     myNewWindow.Height     = cfg.DepData.ScreenHeight - 10;
  1491.     myNewWindow.Flags     &= ~(WINDOWSIZING | WINDOWDRAG);
  1492.  
  1493.     }
  1494.   else  myNewWindow.Height = cfg.DepData.ScreenHeight;
  1495.   myWindow                 = OpenWindow(&myNewWindow);
  1496.   if (!myWindow)
  1497.     {
  1498.     if(myScreen)
  1499.       {
  1500.       CloseScreen(myScreen);
  1501.       myScreen = NULL;
  1502.  
  1503.       }
  1504.     return(-2);
  1505.  
  1506.     };
  1507.   if (myScreen)
  1508.     {
  1509.     tmpcolors[0] = cfg.DepData.Color0;
  1510.     tmpcolors[1] = cfg.DepData.Color1;
  1511.     LoadRGB4(ViewPortAddress(myWindow),tmpcolors,2);
  1512.     ((struct Process *)FindTask(0))->pr_WindowPtr = (APTR)myWindow;
  1513.  
  1514.     };
  1515.   consoleReadPort = CreatePort(0,0);
  1516.   if (!consoleReadPort)
  1517.     {
  1518.     erred = 3;
  1519.  
  1520.     }
  1521.   if (!erred)
  1522.     {
  1523.     consoleReadMsg = (struct IOStdReq *)CreateExtIO(consoleReadPort, sizeof(struct IOStdReq));
  1524.     if (!consoleReadMsg)
  1525.       {
  1526.       erred = 4;
  1527.  
  1528.       }
  1529.  
  1530.     }
  1531.   if (!erred)
  1532.     {
  1533.     consoleWritePort = CreatePort(0,0);
  1534.     if (!consoleWritePort)
  1535.       {
  1536.       erred = 5;
  1537.  
  1538.       }
  1539.  
  1540.     }
  1541.   if (!erred)
  1542.     {
  1543.     consoleWriteMsg = (struct IOStdReq *)CreateExtIO(consoleWritePort, sizeof(struct IOStdReq));
  1544.     if (!consoleWriteMsg)
  1545.       {
  1546.       erred = 6;
  1547.  
  1548.       }
  1549.  
  1550.     }
  1551.   if (!erred)
  1552.     {
  1553.     consoleReadMsg->io_Data = (APTR)myWindow;
  1554.     consoleReadMsg->io_Length = sizeof(struct Window);
  1555.     error = OpenDevice("console.device",0,(struct IORequest *)consoleReadMsg,0);
  1556.     if (error)
  1557.       {
  1558.       erred = 7;
  1559.  
  1560.       }
  1561.  
  1562.     }
  1563.   if (!erred)
  1564.     {
  1565.     consoleWriteMsg->io_Data = (APTR)myWindow;
  1566.     consoleWriteMsg->io_Length = sizeof(struct Window);
  1567.     consoleWriteMsg->io_Device = consoleReadMsg->io_Device;
  1568.     consoleWriteMsg->io_Unit = consoleReadMsg->io_Unit;
  1569.     ConOpen = TRUE;
  1570.     printf("Console opened: Columns = %d, Rows = %d\n ",
  1571.     myNewWindow.Width / myWindow->RPort->TxWidth, (myNewWindow.Height - myWindow->RPort->TxHeight - 2) / myWindow->RPort->TxHeight);
  1572.     QueueRead(consoleReadMsg,&conletter);
  1573.  
  1574.     }
  1575.   ReActivate_Window();
  1576.   if (erred)
  1577.     {
  1578.     CloseConsoleStuff();
  1579.  
  1580.     }
  1581.   return(0-erred);
  1582.  
  1583.   }
  1584. int CloseConsoleStuff(void)
  1585.   {
  1586.   Do_Stack_Check();
  1587.   UnQueueRead();
  1588.   if (ConOpen)  CloseDevice((struct IORequest *)consoleReadMsg);
  1589.   ConOpen = FALSE;
  1590.   if (consoleWriteMsg)
  1591.     {
  1592.     DeleteExtIO((struct IORequest *)consoleWriteMsg);
  1593.     consoleWriteMsg = NULL;
  1594.  
  1595.     }
  1596.   if (consoleWritePort)
  1597.     {
  1598.     DeletePort(consoleWritePort);
  1599.     consoleWritePort = NULL;
  1600.  
  1601.     }
  1602.   if (consoleReadMsg)
  1603.     {
  1604.     DeleteExtIO((struct IORequest *)consoleReadMsg);
  1605.     consoleReadMsg = NULL;
  1606.  
  1607.     }
  1608.   if (consoleReadPort)
  1609.     {
  1610.     DeletePort(consoleReadPort);
  1611.     consoleReadPort = NULL;
  1612.  
  1613.     }
  1614.   if (myWindow)
  1615.     {
  1616.     if (((struct Process *)FindTask(0))->pr_WindowPtr == myWindow)
  1617.     ((struct Process *)FindTask(0))->pr_WindowPtr = (APTR)NULL;
  1618.     CloseWindow(myWindow);
  1619.     myWindow = NULL;
  1620.  
  1621.     }
  1622.   if (myScreen)
  1623.     {
  1624.     CloseScreen(myScreen);
  1625.     myScreen = NULL;
  1626.  
  1627.     }
  1628.   return(TRUE);
  1629.  
  1630.   }
  1631. struct Message *MyGetMsg(struct MsgPort *MyMsgPort)
  1632.   {
  1633.   struct Message *RepliedMessage;
  1634.   Do_Stack_Check();
  1635.   if (RepliedMessage = GetMsg(MyMsgPort))
  1636.     {
  1637.     SetSignal(0L,(1L << MyMsgPort->mp_SigBit));
  1638.  
  1639.     }
  1640.   return(RepliedMessage);
  1641.  
  1642.   }
  1643. int SysdepCheckArg(char *arg)
  1644.   {
  1645.   Do_Stack_Check();
  1646.   return(0);
  1647.  
  1648.   }
  1649. /*
  1650.  * CitSystem()
  1651.  *
  1652.  * This function formats the format & arguments and then runs the result via
  1653.  * system().
  1654.  */
  1655. int CitSystem(char RestoreVideo, char *format, ...)
  1656. {
  1657.     va_list argptr;
  1658.     char *garp;
  1659.     extern char *bigbuffer;
  1660.     Do_Stack_Check();
  1661.     garp = bigbuffer;
  1662.     va_start(argptr, format);
  1663.     vsprintf(garp, format, argptr);
  1664.     va_end(argptr);
  1665. /*    if (RestoreVideo) StopVideo();  */
  1666.     Jsystem(garp);
  1667. /*    if (RestoreVideo) VideoInit();  */
  1668.     return 0;
  1669. }
  1670. unsigned long S_min = 0xFFFFFFFF;  /* min value seen */
  1671. unsigned long S_max = 0x00000000;  /* max value seen */
  1672. void Do_Stack_Check()
  1673.   {
  1674.   unsigned long S_current;
  1675.   S_current = getreg(REG_A7);  /* grab current stack pointer */
  1676.   if( S_current < S_min )S_min = S_current;
  1677.   if( S_current > S_max )S_max = S_current;
  1678.   }
  1679. /*
  1680. ** functions for caller count and user privledges
  1681. */
  1682. char logcall[100];
  1683. long Get_Call_Count()
  1684.   {
  1685.   FILE *ip;
  1686.   long count=0;
  1687.   if( cfg.Audit == 0)return 0;  /* exit if the Sysop has not configed Auditing*/
  1688.   makeAuditName(logcall, "user_count.sys");
  1689.   if( (ip = fopen(logcall,"r")) != NULL)
  1690.     {
  1691.     fread(&count,4,1,ip);
  1692.     fclose(ip);
  1693.     };
  1694.   return count;
  1695.   }
  1696.  
  1697. void Update_Caller_Count()
  1698.   {
  1699.   FILE *ip;
  1700.   long count=0;
  1701.   if( cfg.Audit == 0 ) return; /* Audit Area not setup */
  1702.   makeAuditName(logcall, "user_count.sys");
  1703.   if( (ip = fopen(logcall,"rb")) != NULL)
  1704.     {
  1705.     fread(&count,4,1,ip);
  1706.     fclose(ip);
  1707.     };
  1708.   if( (ip = fopen(logcall,"wb")) != NULL)
  1709.     {
  1710.     fseek(ip,0,SEEK_SET);
  1711.     count++;
  1712.     fwrite(&count,4,1,ip);
  1713.     fclose(ip);
  1714.     };
  1715.   }
  1716.  
  1717. char *Display_Privledges()
  1718.   {
  1719.   extern char      loggedIn;  /* Are we logged in?       */
  1720.   int count=0;                /* check for no privileges */
  1721.   logcall[0] = '\0';          /* initialize string       */
  1722.   if( loggedIn )
  1723.     {
  1724.     if (logBuf.lbflags.AIDE)
  1725.       {
  1726.       count++;
  1727.       strcat(logcall,"Aide, ");
  1728.       };
  1729.  
  1730.     if (logBuf.lbflags.NET_PRIVS)
  1731.       {
  1732.       count++;
  1733.       strcat(logcall,"NET, ");
  1734.       };
  1735.  
  1736.     if (logBuf.lbflags.DOOR_PRIVS)
  1737.       {
  1738.       count++;
  1739.       strcat(logcall,"Door, ");
  1740.       };
  1741.  
  1742.     if (logBuf.lbflags.DL_PRIVS)
  1743.       {
  1744.       count++;
  1745.       strcat(logcall,"File, ");
  1746.       };
  1747.  
  1748.     if (logBuf.lbflags.PERMANENT)
  1749.       {
  1750.       count++;
  1751.       strcat(logcall,"Permanent, ");
  1752.       };
  1753.  
  1754.     if (logBuf.lbflags.TWIT)
  1755.       {
  1756.       count++;
  1757.       logcall[0]='\0';
  1758.       strcat(logcall,"Full ");
  1759.       };
  1760.     };
  1761.   if( count == 0)strcpy( logcall, " No ");
  1762.   count = strlen(logcall);
  1763.   if( logcall[count-2] == ',')logcall[count-2] = '\0';
  1764.   return &logcall[0];
  1765.   }
  1766. /*
  1767. void Debug_space()
  1768.   {
  1769.   short i;
  1770.   for(i=0;i<level;i++)splitF(netLog," ");
  1771.   }
  1772. void Debug_Message(struct Message *Msg)
  1773.   {
  1774.   level++;
  1775.   Debug_space();splitF(netLog," struct Message:%08lX\n",Msg);
  1776.   level--;
  1777.   }
  1778. void Debug_Device( struct Device *Dev)
  1779.   {
  1780.   level++;
  1781.   Debug_space();splitF(netLog," struct Device:%08lX\n",Dev);  level--;
  1782.   }
  1783. void Debug_Unit(   struct Unit *Un)
  1784.   {
  1785.   level++;
  1786.   Debug_space();splitF(netLog," struct Unit :%08lX\n",Un);  level--;
  1787.   level--;
  1788.   }
  1789. int debug_count=0;
  1790. void DebugIoStdReq(struct IOStdReq *Std)
  1791.   {
  1792.   Debug_space();splitF(netLog,"struct IOStdReq:%08lX\n",Std);
  1793.   level++;
  1794.   Debug_Message(&Std->io_Message);
  1795.   Debug_Device( Std->io_Device);
  1796.   Debug_Unit(   Std->io_Unit);
  1797.   Debug_space();splitF(netLog,"io_Command:%04X\n",Std->io_Command);
  1798.   Debug_space();splitF(netLog,"  io_Flags:%02X\n",Std->io_Flags);
  1799.   Debug_space();splitF(netLog,"  io_Error:%02X\n",Std->io_Error);
  1800.   Debug_space();splitF(netLog," io_Actual:%08lX\n",Std->io_Actual);
  1801.   Debug_space();splitF(netLog," io_Length:%08lX\n",Std->io_Length);
  1802.   Debug_space();splitF(netLog,"   io_Data:%08lX\n",Std->io_Data);
  1803.   Debug_space();splitF(netLog," io_Offset:%08lX\n",Std->io_Offset);
  1804.   level--;
  1805.   }
  1806. void  DebugIoRequest (char * string,struct IOExtSer *iorequest)
  1807.   {
  1808.         int  mask = iorequest->io_SerFlags;
  1809.   if (!cfg.BoolFlags.debug)return;
  1810.   if( (debug_count++ % 1000 ) != 0 )return;
  1811.   Debug_space();splitF(netLog," %s=struct IOExtSer:%08lX\n",string,iorequest);
  1812.   DebugIoStdReq(&iorequest->IOSer);
  1813.   Debug_space();splitF(netLog,"CtlChar    0x%lx \n", iorequest->io_CtlChar);
  1814.   Debug_space();splitF(netLog,"RBufLen    %ld   \n", iorequest->io_RBufLen);
  1815.   Debug_space();splitF(netLog,"ExtFlags   0x%lx \n", iorequest->io_ExtFlags);
  1816.   Debug_space();splitF(netLog,"Baud       %ld   \n", iorequest->io_Baud);
  1817.   Debug_space();splitF(netLog,"BrkTime    %ld   \n", iorequest->io_BrkTime);
  1818.   Debug_space();splitF(netLog,"ReadLen    %ld   \n", iorequest->io_ReadLen);
  1819.   Debug_space();splitF(netLog,"WriteLen   %ld   \n", iorequest->io_WriteLen);
  1820.   Debug_space();splitF(netLog,"StopBits   %ld   \n", iorequest->io_StopBits);
  1821.   Debug_space();splitF(netLog,"SerFlags   0x%lx \n", iorequest->io_SerFlags);
  1822.         if (mask)
  1823.           {
  1824.     Debug_space();splitF(netLog,"           ");
  1825.                 if (mask & SERF_XDISABLED)  Debug_space();splitF(netLog,"XDISABLED ");
  1826.                 if (mask & SERF_EOFMODE)    Debug_space();splitF(netLog,"EOFMODE ");
  1827.                 if (mask & SERF_SHARED)     Debug_space();splitF(netLog,"SHARED ");
  1828.                 if (mask & SERF_RAD_BOOGIE) Debug_space();splitF(netLog,"RAD_BOOGIE ");
  1829.                 if (mask & SERF_QUEUEDBRK)  Debug_space();splitF(netLog,"QUEUEDBRK ");
  1830.                 if (mask & SERF_7WIRE)      Debug_space();splitF(netLog,"7WIRE ");
  1831.                 if (mask & SERF_PARTY_ODD)  Debug_space();splitF(netLog,"PARTY_ODD ");
  1832.                 if (mask & SERF_PARTY_ON)   Debug_space();splitF(netLog,"PARTY_ON");
  1833.     Debug_space();splitF(netLog,"\n");
  1834.           }
  1835.   Debug_space();splitF(netLog,"Status     0x%lx \n", iorequest->io_Status);
  1836.         return;
  1837. }
  1838. */
  1839.